// pages/master/propaganda/page/push/page/favourActivity/favourActivity.js
const app = getApp();
const db = wx.cloud.database()
const _ = db.command
const faDB=db.collection('favourActivity')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeList:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
  that.getactiveList()
  },
  getactiveList:function(){
    let that = this
    faDB//.orderBy('_id', 'desc')
    .get().then(res=>{
      let data = res.data
      data.unshift("添加")
      // console.log(data)
      that.setData({
        activeList:data
      })
      console.log(that.data.activeList)
    })
  },
  longClick:function(e){
    let that =this
      let id = e.currentTarget.dataset.id
      wx.showModal({
        title: '提示',
        content: '确定删除该活动？',
        success (res) {
        if (res.confirm) {
        console.log('用户点击确定')
        wx.showLoading()
          wx.cloud.callFunction({
            name:'deleteFavorActivity',
            data:{
              id:id
            },success(res){
              that.getactiveList()
              wx.hideLoading()
            }
          })
        } else if (res.cancel) {
        console.log('用户点击取消')
        }
        }
        })
    
  },
  previewImage: function (e) {
    var url = e.currentTarget.dataset.url
    var urls = []
    urls.push(e.currentTarget.dataset.urls)
    console.log(url,urls)
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: urls // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})